/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package satb.base.view;

import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;

import satb.controller.CollarDataController;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.stage.Stage;

/**
 * FXML Controller class
 *
 * @author Marcel
 */
public class CollarDataView implements Initializable {

    private Stage subStage;
    private CollarDataController controller;
    
    @FXML private ComboBox<String> cmbFileType;
    @FXML private Button btnOpen;
    @FXML private Button btnClose;
    
    public CollarDataView() 
    { 
    	cmbFileType = new ComboBox<>();
    	controller = new CollarDataController();
    }
    
    
    public void execute()
    {
        subStage = new Stage();
        subStage.setTitle("Sistema Coletor de Dados");
        subStage.setResizable(false);
        
        try 
        {
            Parent root = FXMLLoader.load(getClass().getResource("fxml/CollarData.fxml"));
            Scene scene = new Scene(root);
        
            subStage.setScene(scene);
            subStage.show();
        } 
        catch (IOException ex) 
        {
            Logger.getLogger(CollarDataController.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        
    }

    
    /**
     * Initializes the controller class.
     */
    @Override
    public void initialize(URL url, ResourceBundle rb) 
    {
        assert cmbFileType != null : "fx:id=\"cmbFileType\" was not injected: check your FXML file 'CollarData.fxml'.";
       
        // Initialize your logic here: all @FXML variables will have been injected
        cmbFileType.getItems().clear();
        cmbFileType.getItems().addAll("ARFF", "OTAG", "OTAG2nd", "VenusGPS");
    }   
    
    
    @FXML
    private void openFile(ActionEvent event) 
    {
    	switch(cmbFileType.getValue())
        {
            case "OTAG":
                controller.readTxt();
                break;
                
            case "OTAG2nd":
                controller.readTxt2nd("0007");
                break;
            
            case "VenusGPS":
                controller.readTxtVenus("0007");
                break;
     
            case "ARFF":
                try 
                {
                    controller.readARFF();
                } 
                catch (Exception ex) 
                {
                    Logger.getLogger(CollarDataView.class.getName()).log(Level.SEVERE, null, ex);
                }
                break;
        }
            
    }
    
    
    @FXML
    private void close(ActionEvent event) 
    {
    	// get a handle to the stage
        Stage stage = (Stage) btnClose.getScene().getWindow();
        // do what you have to do
        stage.close();
    }
    
    
    
}